package servlet_teacher;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TeacherDeleteMessageServlet
 */
@WebServlet("/servlet_deletemessage_teacher")
public class TeacherDeleteMessageServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public TeacherDeleteMessageServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		ServletContext application = request.getServletContext();

		/* System.out.println(request.getParameter("id")); */
		if (request.getParameter("id") != null) {
			int index = Integer.parseInt(request.getParameter("id"));
			if (application.getAttribute("message") != null) {
				@SuppressWarnings("unchecked")
				List<String> messagelist = (List<String>) application.getAttribute("message");
				messagelist.remove(index);
			}
		}
		response.sendRedirect("jsp/teacher/teacher_manage_notify.jsp");

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
